package com.ljx.funchat.user.controller;

import com.ljx.funchat.common.domain.vo.resp.ApiResult;
import com.ljx.funchat.common.utils.RequestHolder;
import com.ljx.funchat.user.domain.vo.req.UserBatchReq;
import com.ljx.funchat.user.domain.vo.req.UserInfoUpdateReq;
import com.ljx.funchat.user.domain.vo.resp.UserBatchResp;
import com.ljx.funchat.user.domain.vo.resp.UserResp;
import com.ljx.funchat.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author LiJunXi
 * @since 2024-02-13
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("获取用户信息列表【缓存】")
    @PostMapping("/info/batch")
    public ApiResult<List<UserBatchResp>> getUserBatch(@Valid @RequestBody UserBatchReq req){
        Long uid = RequestHolder.get().getUid();

        return ApiResult.success(userService.getUserBath(uid, req));
    }


    @ApiOperation("/查询某个用户详情")
    @GetMapping("/public/info")
    public ApiResult<UserResp> getUserInfo(@RequestParam("uid") Long uid){

        return ApiResult.success(userService.getUserInfo(uid));
    }

    @ApiOperation("修改用户信息")
    @PutMapping("/info/update")
    public ApiResult<Void> updateUserInfo(@RequestBody UserInfoUpdateReq req){
        Long uid = RequestHolder.get().getUid();
        userService.updateUserInfo(uid, req);

        return ApiResult.success();
    }


}

